import App from "../views/app.vue";
import lazyLoading from "src/config/lazyLoading.js";

export const config = {
  routers: {
    items: [
      {
        name: "pc",
        path: "/pc",
        meta: {
          title: "PC页面",
          link: "pc/index.vue"
        },
        component: lazyLoading("pc", true)
      },
      {
        name: "download",
        path: "/download",
        meta: {
          title: "download",
          link: "pc/download.vue"
        },
        component: lazyLoading("pc/download")
      },
      {
        name: "firmBargain",
        path: "/firmBargain",
        meta: {
          title: "firmBargain",
          link: "pc/firmBargain.vue"
        },
        component: lazyLoading("pc/firmBargain")
      },
      {
        name: "futuresLive",
        path: "/futuresLive",
        meta: {
          title: "futuresLive",
          link: "pc/futuresLive.vue"
        },
        component: lazyLoading("pc/futuresLive")
      }, {
        name: "information",
        path: "/information",
        meta: {
          title: "information",
          link: "pc/information.vue"
        },
        component: lazyLoading("pc/information")
      }, {
        name: "mockTrading",
        path: "/mockTrading",
        meta: {
          title: "mockTrading",
          link: "pc/mockTrading.vue"
        },
        component: lazyLoading("pc/mockTrading")
      }, {
        name: "information",
        path: "/information",
        meta: {
          title: "information",
          link: "pc/information.vue"
        },
        component: lazyLoading("pc/information")
      }, {
        name: "register",
        path: "/register",
        meta: {
          title: "register",
          link: "pc/register.vue"
        },
        component: lazyLoading("pc/register")
      }, {
        name: "specialOffer",
        path: "/specialOffer",
        meta: {
          title: "specialOffer",
          link: "pc/specialOffer.vue"
        },
        component: lazyLoading("pc/specialOffer")
      }
    ]
  }
};

/**
 * 配置多入口页面 挂载组件等
 */
export default [
  {
    path: "/",
    component: App,
    children: [
      {
        path: "/", //首页
        name: "/",
        meta: { title: "首页" },
        component: lazyLoading("pc", true)
      },
      ...generateRoutesFromMenu(config.routers.items)
    ]
  }
];

// Menu should have 2 levels.
function generateRoutesFromMenu(menu = [], routes = []) {
  for (let i = 0, l = menu.length; i < l; i++) {
    let item = menu[i];
    if (item.path) {
      routes.push(item);
    }
    if (!item.component) {
      generateRoutesFromMenu(item.children, routes);
    }
  }
  return routes;
}
